package com.todo.member.infrastructure.repository.impl;

import com.todo.common.common.entity.response.page.PageResult;
import com.todo.common.utils.StringUtils;
import com.todo.member.infrastructure.entity.condition.MemberPrivilegeInfoCondition;
import com.todo.member.infrastructure.entity.po.MemberPrivilegeInfoPO;
import com.todo.member.infrastructure.mapper.MemberPrivilegeInfoMapper;
import com.todo.member.infrastructure.repository.MemberPrivilegeInfoRepository;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * @author azhebuxing
 * @date 2025/2/11 11:31
 * @description
 */
@Repository
public class MemberPrivilegeInfoRepositoryImpl implements MemberPrivilegeInfoRepository {

    @Resource
    private MemberPrivilegeInfoMapper memberPrivilegeInfoMapper;

    @Override
    public Boolean insertMemberPrivilegeInfoPO(MemberPrivilegeInfoPO memberPrivilegeInfoPO) {
        if (memberPrivilegeInfoPO == null){
            return false;
        }
        if (memberPrivilegeInfoPO.getPrivilegeName() == null || memberPrivilegeInfoPO.getPrivilegeCode() == null){
            return false;
        }
        return memberPrivilegeInfoMapper.insertMemberPrivilegeInfoPO(memberPrivilegeInfoPO) > 0;
    }

    @Override
    public Boolean updateMemberPrivilegeInfoPOById(MemberPrivilegeInfoPO memberPrivilegeInfoPO) {
        if (memberPrivilegeInfoPO == null || memberPrivilegeInfoPO.getId() == null){
            return false;
        }
        return memberPrivilegeInfoMapper.updateMemberPrivilegeInfoPOById(memberPrivilegeInfoPO) > 0;
    }

    @Override
    public Boolean removeMemberPrivilegeInfoPOById(Long id) {
        if (id == null || id < 0){
            return false;
        }
        return memberPrivilegeInfoMapper.removeMemberPrivilegeInfoPOById(id);
    }

    @Override
    public MemberPrivilegeInfoPO queryMemberPrivilegeInfoPOById(Long id) {
        if (id == null || id < 0){
            return null;
        }
        return memberPrivilegeInfoMapper.queryMemberPrivilegeInfoPOById(id);
    }

    @Override
    public MemberPrivilegeInfoPO queryMemberPrivilegeInfoPOByPrivilegeCode(String privilegeCode) {
        if (StringUtils.isBlank(privilegeCode)){
            return null;
        }
        return memberPrivilegeInfoMapper.queryMemberPrivilegeInfoPOByPrivilegeCode(privilegeCode);
    }

    public List<MemberPrivilegeInfoPO> queryMemberPrivilegeInfoPOByCodeList(List<String> privilegeCodeList) {
        if (CollectionUtils.isEmpty(privilegeCodeList)){
            return Collections.emptyList();
        }
        return memberPrivilegeInfoMapper.queryMemberPrivilegeInfoPOByCodeList(privilegeCodeList);
    }

    @Override
    public MemberPrivilegeInfoPO queryMemberPrivilegeInfoPOByPrivilegeName(String privilegeName) {
        if (StringUtils.isBlank(privilegeName)){
            return null;
        }
        return memberPrivilegeInfoMapper.queryMemberPrivilegeInfoPOByPrivilegeName(privilegeName);
    }

    @Override
    public PageResult<MemberPrivilegeInfoPO> queryMemberPrivilegeInfoPOByPage(MemberPrivilegeInfoCondition memberPrivilegeInfoCondition) {
        return null;
    }
}
